﻿using System;
using AutoMapper;

namespace good1.Web.Controllers.Utility
{
    public static class MapperHelper
    {
        public class DateTimeTypeConverter : ITypeConverter<DateTime, string>
        {
            public string Convert(DateTime source)
            {
                return source.ToString("dd-MMM-yyyy");
            }
        }

        public class StringDateTimeTypeConverter : ITypeConverter<string, DateTime>
        {
            public DateTime Convert(string source)
            {
                return System.Convert.ToDateTime(source);
            }
        }

        public class EnumConverter<TEnum> : ITypeConverter<TEnum, string> where TEnum : struct 
        {
            public string Convert(TEnum source)
            {
                return source.ToString();
            }
        }

        public class StringEnumConverter<TEnum> : ITypeConverter<string, TEnum> where TEnum : struct 
        {
            public TEnum Convert(string source)
            {
                return (TEnum)Enum.Parse(typeof(TEnum), source);
            }
        }

        public class IntEnumConverter<TEnum> : ITypeConverter<int, TEnum> where TEnum : struct
        {
            public TEnum Convert(int source)
            {
                return (TEnum)(object)source;  //this does assume that TEnum is of type int
            }
        }


    }
}
